
var orders = localStorage.getItem('orders') ? JSON.parse(localStorage.getItem('orders')) : []
var none = document.getElementsByClassName('none')[0]
var travels = document.getElementsByClassName('travels')[0]
var old = document.getElementsByClassName('old')[0]
function getorders() {
  if (orders.length) {
    none.style.display = 'none'
    for (var i = 0; i < orders.length; i++) {
      var html = `
      <div class="travel-item flex">
        <div class="con flex align-items">
          <img src="${orders[i].imgT}" alt="" style="height: 100%">
          <div>${orders[i].name}</div>
        </div>
        <div class="order flex align-items">
          <div>${orders[i].name}</div>
          <div>${orders[i].title}</div>
          <div>数量：${orders[i].num}</div>
        </div>
        <div class="total flex align-items">${orders[i].totalNum}元</div>
        <div class="opt flex align-items">
          <div class="flex">
            <div class="btn pay">立即预定</div>
            <div class="btn remove" index="${i}">删除</div>
          </div>
        </div>
      </div>
      `
      $('.travels').append(html)
    }
  } else {
    none.style.display = 'block'
  }
}
getorders()
var remove = document.getElementsByClassName('remove')
console.log(remove)
for (var j = 0; j < remove.length; j++) {
  remove[j].onclick = function () {
    console.log($(this).attr('index'))
    orders.splice($(this).attr('index'), 1)
    console.log(orders)
    localStorage.setItem('orders', JSON.stringify(orders))
    $('.travels').empty()
    getorders()
  }
}